|
|
|
|
|
|
|
8. Arrange the labels next to the appropriate text boxes. Click the UserControl object, and resize it so that the constituent controls fit neatly inside. You can resize your control by using the sizing handles or changing the Height and Width properties in the Properties window. The sample control should be around 4395 twips wide by 3600 twips high and look like the one in Figure 14.2. |
|
|
|
|
|
|
|
|
Figure 14.2
The full set of constituent controls
is drawn on the UserControl object. |
|
|
|
|
|
|
|
|
9. As with all VB projects, saving your work is important. Do so now before continuing. |
|
|
|
|
|
|
|
|
Adding Resize Code to the Control |
|
|
|
|
|
|
|
|
As you know from using standard controls such as a text box, you can adjust the size of a control in design mode by using the mouse or by setting its Height and Width properties. A TextBox control responds appropriately by automatically redrawing itself at the new size. When you are designing your own ActiveX control, especially one that is made up of existing controls, resizing is an important consideration. As you resize your control, you need to take action to make sure that the constituent controls are not hidden from the user or arranged in a way that prevents useful operation of the control. |
|
|
|
|
|
|
|
|
To handle this control, you need to add code that responds to the Resize event of the UserControl object. This code will be executed whenever someone is drawing your control in a Visual Basic project. To add the necessary code for the Address control, take the following steps: |
|
|
|
|
|
|
|
|
1. Double-click the UserControl object, as you would a standard form. The Code window opens. |
|
|
|
|
|
|
|
|
2. From the Procedures box of the Code window, select the Resize event. |
|
|
|
|
|
|
|
|
3. Add the following lines of code to the UserControl_Resize event: |
|
|
|
|
|
|
|
|
Private Sub UserControl_Resize()
With UserControl
'Enforce minimum dimensions
If .Height < 3615 Then .Height = 3615
If .Width < 2175 Then .Width = 2175
'Resize objects on the control
txtName.Width = .ScaleWidth - 500
txtStreet.Width = .ScaleWidth - 500
txtCity.Width = .ScaleWidth - 500
txtZip.Width = .ScaleWidth / 2 - 500 |
|
|
|
|
|